<template>
  <a-modal 
    :visible="visible"
    :title="title"
    :maskClosable="false"
    :destroyOnClose="true"
    :keyboard="false"
    :bodyStyle="{background:'#F8F8F8',padding:'0px'}"
    @cancel="closeModal()"
    width="500px">
    <a-carousel autoplay dotPosition="bottom">
      <img v-for="(item,index) in dataInfo.imgList" :key="index" class="carousel_img" :src="item"/>
    </a-carousel>
    <section class="main">      
      <div class="title" v-if="dataInfo.productName || dataInfo.goodsName">{{dataInfo.productName || dataInfo.goodsName}}</div>
      <div class="specs" v-if="dataInfo.productPoints || dataInfo.goodsSellingPoint">{{dataInfo.productPoints || dataInfo.goodsSellingPoint}}</div>
      <div class="price">
        <div class="left" v-if="dataInfo.goodsSpecList && dataInfo.goodsSpecList.length>0">
          <span class="price1">￥{{dataInfo.goodsSpecList[0].salePrice || 0}}</span>
          <span class="price2">￥{{dataInfo.goodsSpecList[0].marketPrice || 0}}</span>
        </div>
        <div class="right">
          已售0件
        </div>
      </div>
    </section>
    <!-- <section class="discount">
      <div>优惠<span class="tab">满100减20</span></div>
      <span class="collect_coupons_bg">领劵 &gt;</span>
    </section> -->
    <section class="detail">
      <a-tabs default-active-key="1">
        <a-tab-pane key="1" tab="产品详情">
          <div class="content" v-html="dataInfo.productInfo || dataInfo.goodsDetails"></div>
        </a-tab-pane>
        <a-tab-pane key="2" tab="评论">
          
        </a-tab-pane>
      </a-tabs>
    </section>
    <template slot="footer">
      <a-button @click="closeModal()">关闭</a-button>
    </template>
  </a-modal>
</template>
<script>
import deepCopy from '@/utils/deepCopy'
export default {
  components:{
   
  },
  props: {
    visible:{
      type:Boolean,
      default:false,
    },
    data:{
      type:Object,
      default(){
        return {};
      }
    }
  },
  computed: {
    title () {
      return '商品预览'
    },
  },
  data () {
    return {
      dataInfo:{},
    }
  },
  watch: {
    visible(newVal){
      if(newVal){
        let dataInfo=deepCopy(this.data);
        dataInfo.imgList=dataInfo.imgList && dataInfo.imgList.split(',') || dataInfo.goodsPictures && dataInfo.goodsPictures.split(',') || [];
        this.dataInfo=dataInfo;
        console.log('this.dataInfo',this.dataInfo)
      }
    },
  },
  created(){
    
  },
  mounted () {

  },
  methods: {
    //获取型号标题和值
    async getTitleLabelAndValue(id){
        if(!parseInt(id)){
            return {};
        }
        let res = await this.$get('/goods/modelnorm/id',{
            id
        },false,true);
        if(res && res.returnCode=='1000'){
            return {
                label:(res.dataInfo || {}).normName || '',
                value:id,
            }
        }
        else {
            return {};
        }
    },
    closeModal (freshTable) {
      this.$emit('cancel', freshTable)
    }
  }
}
</script>

<style lang="less" scoped>
section{
  padding:10px 20px;
  background:#fff;
}
.carousel_img{
  width:100%;
  height:300px;
  background:#777;
  object-fit: cover;
}
.title{    
  font-size: 18px;
  font-weight: bold;
  line-height: 40px;
  color: #000;
}
.spaces{
  color: #777;
  line-height: 30px;
}
.price{
  display:flex;
  align-items: center;
  justify-content: space-between;
  line-height: 30px;
  margin-top:5px;
  .price1{
    font-size: 20px;
    color: #000;
  }
  .price2{
    color: #777;
    text-decoration: line-through;
    margin-left: 10px;
  }
}
.discount{
  margin-top:10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .collect_coupons_bg{
    width:75px;
    height:35px;
    display:block;
    text-indent: 25px;
    color:#fff;
    font-size:12px;
    line-height: 35px;
    position: relative;
    right: -20px;
    background:url("~@/assets/images/product/app_icon_coupon.png") 50% 50%/cover no-repeat;
  }
  .tab{
    background:#FFE7E7;
    color:#F0A4A0;
    padding:3px 10px;
    border-radius: 3px;
    margin-left: 10px;
    font-size: 12px;
  }
}
.detail{
  margin-top:10px;
  /deep/ img{
    max-width: 100%;
  }
}
</style>
